package com.office.web.controller.file.server.impl;

import com.office.common.utils.SecurityUtils;
import com.office.web.controller.file.domain.FileUploadDomain;
import com.office.web.controller.file.mapper.FileUploadMapper;
import com.office.web.controller.file.server.FileUploadServer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: 柒月
 * @date: 2025/5/28 下午2:33
 * @version: 1.0
 */
@Service
public class FileUploadServerImpl implements FileUploadServer {

    @Resource
    private FileUploadMapper fileUploadMapper;


    /**
     * @param originalName 原始文件名
     * @param storedName   存储在 mioin 中的文件名
     * @param url          访问连接
     * @param size         文件大小
     * @param contentType  文件类型
     * @return 插入数据后的主键
     */
    @Override
    public Long addFileUpload(String originalName, String storedName, String url, long size, String contentType) {

        FileUploadDomain fileUploadDomain = new FileUploadDomain(contentType, storedName, size, originalName, url);
        // 数据库插入
        fileUploadMapper.insertFileUploadInfo(fileUploadDomain);
        // 返回主键
        return fileUploadDomain.getId();
    }

    /**
     * @param fileName 删除的文件名
     * @return 影响的结果
     */
    @Override
    public Integer deleteFileByName(String fileName) {
        return fileUploadMapper.deleteFileByName(fileName);
    }
}
